-- NewTeamBossSkillRender 地下城boss信息技能说明render

local panelWidth = 0 -- 原始panel宽
local panelSkillHeight = 0
local skillNameHeight = 0 -- 技能名原始高
local skillDescWidth = 0 -- 技能描述文本原始宽度
local skillDescHeight = 0 -- 技能描述文本原始
local eachLineHeight = 0 -- 单行文本高
--local numWordOfEachLine = 14

local ClassRef = app.mvc.createRenderClass(...)

function ClassRef.createWithData(data, node)
	local sprite = ClassRef.extend(node or cc.CSLoader:createNode(Res.CosplaySkillNode))
	if node == nil then
		ccui.Helper:doLayout(sprite)
	end
	sprite:init(data)
	return sprite
end
function ClassRef.create(node)
    return ClassRef.createWithData(nil, node)
end

-- data = Skill
function ClassRef:init(data)
	self.super.init(self, data)

	self:setContentSize(self._ui.Panel:getContentSize())
	panelWidth = self._ui.Panel:getContentSize2()

	skillDescWidth, skillDescHeight = self._ui.text:getContentSize2()
	eachLineHeight = skillDescHeight/4

	local _
	_, skillNameHeight = self._ui.name:getContentSize2()
	_, panelSkillHeight = self._ui.Panel_skill:getContentSize2()

	self:refresh()
end

function ClassRef:refresh()
	if self._data then
		local data = self._data
		self._ui.icon:loadTexture( data:getIcon() )
		self._ui.name:setString( data:getName() )
		self._ui.text:setString( data:getDes() )
		self._ui.text:getVirtualRenderer():setDimensions( skillDescWidth, 0 )
		local size = self._ui.text:getVirtualRendererSize()
		--local skillDesHeight = math.ceil( string.utf8len( data:getDes() ) / numWordOfEachLine ) * eachLineHeight
		local skillDesHeight = size.height
		self._ui.text:setContentSize( cc.size( skillDescWidth, skillDesHeight ) )

		-- 以下：调整panel高
		local totalHeight = 0 -- panel总高度
		if skillNameHeight + skillDesHeight < panelSkillHeight then
			totalHeight = 15 + panelSkillHeight + 15
		else
			totalHeight = 15 + skillNameHeight + skillDesHeight + 15
		end
		self._ui.Panel:setContentSize( cc.size( panelWidth, totalHeight ) )
		self:setContentSize( cc.size( panelWidth * self:getScale(), totalHeight * self:getScale() ) )

		ccui.Helper:doLayout( self )
	end
end

return ClassRef
